﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;
using HRM.DAL.Report;

namespace HRM.UI.HRAdminUI.EmpModule
{
    public partial class SearchEmployee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadProject();
                Loadcatagory();
                searchGridDIV.Visible = false;

            }

        }

        private void LoadProject()
        {

            List<Project> projects = new List<Project>();
            ProjectManager manager = new ProjectManager();
            projects = manager.GetAllProjects();
            ddlEmpProject.DataTextField = "ProjectName";
            ddlEmpProject.DataValueField = "Id";
            ddlEmpProject.DataSource = projects;
            ddlEmpProject.DataBind();
            ddlEmpProject.Items.Insert(0, "---Choose Any---");

        }
        private void Loadcatagory()
        {
            List<Catagory> catagories = new List<Catagory>();
            CatagoryManager manager = new CatagoryManager();
            catagories = manager.GetAllCatagories();
            ddempCatagory.DataTextField = "EmpCatagory";
            ddempCatagory.DataValueField = "Id";
            ddempCatagory.DataSource = catagories;
            ddempCatagory.DataBind();
            ddempCatagory.Items.Insert(0, "---Choose Any---");

        }


        protected void SearchCode(object sender, EventArgs e)
        {
            EmployeeManager empManager = new EmployeeManager();
            List<ViewEmployee> employees = new List<ViewEmployee>();
            ViewEmployee aEmployee = new ViewEmployee();
            Code code = new Code();
            code.CodeName = txtSearchCode.Value;
            aEmployee = empManager.SearchEmployeeByCode(code);
            employees.Add(aEmployee);
            searchEmpGrid.DataSource = employees;
            searchEmpGrid.DataBind();
            searchGridDIV.Visible = true;
            MessageforSearchDIV.Visible = false;



        }

        protected void SearchByCatagory(object sender, EventArgs e)
        {
            EmployeeManager empManager = new EmployeeManager();
            List<ViewEmployee> employees = new List<ViewEmployee>();
            Catagory catagory = new Catagory();
            catagory.Id = Convert.ToInt32(ddempCatagory.Value);
            employees = empManager.SearchEmployeeByCatagory(catagory);
            searchEmpGrid.DataSource = employees;
            searchEmpGrid.DataBind();
            searchGridDIV.Visible = true;
            MessageforSearchDIV.Visible = false;
        }

        protected void SearchByProject(object sender, EventArgs e)
        {
            EmployeeManager empManager = new EmployeeManager();
            List<ViewEmployee> employee = new List<ViewEmployee>();
            Project project = new Project();
            project.Id = Convert.ToInt32(ddlEmpProject.Value);
            employee = empManager.SearchEmployeeByProject(project);
            searchEmpGrid.DataSource = employee;
            searchEmpGrid.DataBind();
            searchGridDIV.Visible = true;
            MessageforSearchDIV.Visible = false;
        }

        protected void SearchByStatus(object sender, EventArgs e)
        {
            EmployeeManager empManager = new EmployeeManager();
            List<ViewEmployee> employee = new List<ViewEmployee>();
            Status aStatus = new Status();
            //aStatus.Id = Convert.ToInt32(ddStatus.Value);
            employee = empManager.SearchEmployeeByStatus(ddStatus.Value);
            searchEmpGrid.DataSource = employee;
            searchEmpGrid.DataBind();
            searchGridDIV.Visible = true;
            MessageforSearchDIV.Visible = false;


        }
    }
}